package com.itheima.extend;

/**
 * volatile 保证线程之间变量的可见性 ;
 */
public class VisiableDemo {

    private static volatile boolean flag = true;

    public static void main(String[] args) throws InterruptedException {
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (flag){
                }
            }
        }).start();

        System.out.println("Main ...............");
        Thread.sleep(2000);
        flag = false;
        System.out.println("Over .............");
    }
}
